package com.miracle.controller;

import com.miracle.entity.Product;
import com.miracle.feignclients.ProductClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author jie.xi
 * @date 2022年05月12日 15:27
 */

@RestController
@Slf4j
public class TestOpenFeignController {

    @Autowired
    private ProductClient productClient;


    @GetMapping("/feign/test")
    public String test(){
        log.info("进入测试feign调用的方法");
        String msg = productClient.showMsg();
        log.info("调用商品服务返回信息；[{}]",msg);
        return msg;
    }

    @GetMapping("/feign/test2")
    public Map<String,Object> test2(){
        log.info("进入测试feign调用的方法");
        Map<String, Object> all = productClient.findAll();
        log.info("调用商品服务返回信息；[{}]",all);
        return all;
    }

    @GetMapping("/feign/testGet")
    public Map<String,Object> testGet(String productId){
        log.info("用来测试OpenFeign的Get方式参数传递");
        Map<String, Object> msg = productClient.findOne(productId);
        log.info("调用返回信息：[{}]",msg);
        return msg;
    }

    @GetMapping("/feign/testPost")
    public Map<String,Object> testPost(String name){
        log.info("用来测试OpenFeign的Post方式参数传递");
        Map<String, Object> msg = productClient.save(name);
        log.info("调用返回信息：[{}]",msg);
        return msg;
    }

    @GetMapping("/feign/testPost2")
    public Map<String,Object> testPost2(Product product){
        log.info("用来测试OpenFeign的Post方式参数传递,接收到的商品信息：[{}]",product);
        Map<String, Object> msg = productClient.update(product);
        log.info("调用返回信息：[{}]",msg);
        return msg;
    }

}
